package Repository;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import model.Account;
import model.Assigned;
import model.Lead;
import model.Qualified;


@SuppressWarnings("deprecation")
public class LeadRepository extends Repository{
	public String LeadName,LeadType;
	public Long LeadId;
	private static HashMap<Long,Lead> leadMap = new HashMap<Long,Lead>();
	
	
	
	//private LeadRepository(){}
	/*static{
		Lead lead = new Lead();		
		lead.setName("Mythri") ;
		lead.setLeadDate(new Date(2009, 3, 4));
		lead.setAddress("California");
		lead.setFax("555555151");
		lead.setCity("San Jose");
		lead.setCountry("USA");
		lead.setEmail("mythri@yahoo.com");
		lead.setPhoneNum(650555666);
		lead.setCurrentState(new Qualified());
		lead.setAccount(new Account());
		lead.setSource("phone");
		lead.setZip("95121");
		lead.setProductInterest("PC");
		lead.setSmsObjId(1);
		lead.setManagedByUser(UserRepository.getSalesRep("San Jose"));
		leadMap.put(new Long(1), lead);
		
		lead = new Lead();
		lead.setName("Sandhya") ;
		lead.setLeadDate(new Date(2009, 6, 8));
		lead.setAddress("California");
		lead.setFax("586555151");
		lead.setCity("San Jose");
		lead.setCountry("USA");
		lead.setEmail("Sandhya@yahoo.com");
		lead.setPhoneNum(600505666);
		lead.setCurrentState(new Qualified());
		lead.setAccount(new Account());
		lead.setSource("phone");
		lead.setZip("95121");
		lead.setProductInterest("Laptop");
		lead.setSmsObjId(2);
		lead.setManagedByUser(UserRepository.getSalesRep("San Jose"));
		leadMap.put(new Long(2), lead);
		
		lead = new Lead();
		lead.setName("Aarthi") ;
		lead.setLeadDate(new Date(2009, 6, 4));
		lead.setAddress("California");
		lead.setFax("998555151");
		lead.setCity("San Jose");
		lead.setCountry("USA");
		lead.setEmail("Aarthi@yahoo.com");
		lead.setPhoneNum(608955666);
		lead.setCurrentState(new Assigned());
		lead.setAccount(new Account());
		lead.setSource("phone");
		lead.setZip("95121");
		lead.setProductInterest("PCs");
		lead.setSmsObjId(3);
		leadMap.put(new Long(3), lead);
		
		lead = new Lead();
		lead.setName("Aarthi") ;
		lead.setLeadDate(new Date(2009, 5, 11));
		lead.setAddress("California");
		lead.setFax("650455151");
		lead.setCity("San Jose");
		lead.setCountry("USA");
		lead.setEmail("dhara@yahoo.com");
		lead.setPhoneNum(650205666);
		lead.setCurrentState(new Assigned());
		lead.setAccount(new Account());
		lead.setSource("phone");
		lead.setZip("95121");
		lead.setProductInterest("Laptop");
		lead.setSmsObjId(4);
		leadMap.put(new Long(4), lead);
	}*/
	public Object retrieve(Long id) {
		/*if (smsobjType.equals(SMSConstants.OPPORTUNITY))
		{
			if(Type.equals("Qualified"))
			{
				return Opportunity.get(information.LeadType.equals("Qualified"));
			}
			else if(Type.equals("Prepared"))
			{
				return Opportunity.get(information.LeadType.equals("Prepared"));	
			}
			else if(Type.equals("ProduceQuoted"))
			{
			return Opportunity.get(information.LeadType.equals("ProduceQuoted"));
		
			}
			else if(Type.equals("ApproveQuoted"))
			{
			return Opportunity.get(information.LeadType.equals("ApproveQuoted"));
		
			}
		}	*/
		
		return leadMap.get(id);
	}
	
	
	public void delete(Long id) {
		if(leadMap.containsKey(id))
		leadMap.remove(id);
		
	}
	
	public void insert(Long id,Object obj) {
		leadMap.put(id, (Lead)obj);
				
	}
	
	public void update(Long id, Object updatedObj) {
		leadMap.remove(id);
		leadMap.put(id, (Lead)updatedObj);
		
		
	}


	@Override
	public Object retrieve(String objectType, String ruleType) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public List retrieve(String State) {
		List list =new ArrayList();
		Collection<Lead> c = leadMap.values();
		
		
			for(Lead lead : c )
			{	
				if(lead.getCurrentState().getStateName().equalsIgnoreCase(State))
				{
					list.add(lead);
				}				
			}
			
	return list;
	}


	@Override
	public boolean find(String objName) {
		Collection<Lead> c = leadMap.values();
		int count=0;
		for(Lead lead : c ){
			if(lead.getName().equalsIgnoreCase(objName)){
				count++;
			}
		}
		if(count>1){
			return true;
		}
		
		return false;
	}


	@Override
	public Collection retrieveAll() {
		// TODO Auto-generated method stub
		return null;
	}
	
}
	
	

